//
//  SkeletonTableCell.swift
//  koolcar
//
//  Created by xiantian on 2023/11/14.
//

import UIKit

class SkeletonTableCell: UITableViewCell {
    var imgView: UIImageView = {
        let tempImgView = UIImageView.init(frame: CGRect.init(x: 0, y: 0, width: 100, height: 100))
        tempImgView.isSkeletonable = true
        return tempImgView
    }()
    var titleLab: UILabel = {
        let tempLab = UILabel()
        tempLab.textColor = Theme.titleLabColor
        tempLab.backgroundColor = UIColor.clear
        tempLab.font = UIFont.init(name: Theme.PingFangSCRegular, size: 14)
        tempLab.numberOfLines = 0
        tempLab.lineBreakMode = .byTruncatingTail
        tempLab.textAlignment = .left
        tempLab.isSkeletonable = true
        return tempLab
    }()
    
    var subTitleLab: UILabel = {
        let tempLab = UILabel()
        tempLab.textColor = Theme.titleLabColor
        tempLab.backgroundColor = UIColor.clear
        tempLab.font = UIFont.init(name: Theme.PingFangSCRegular, size: 14)
        tempLab.numberOfLines = 0
        tempLab.lineBreakMode = .byTruncatingTail
        tempLab.textAlignment = .left
        tempLab.isSkeletonable = true
        return tempLab
    }()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.isSkeletonable = true
        self.contentView.addSubview(imgView)
        self.contentView.addSubview(titleLab)
        self.contentView.addSubview(subTitleLab)
        self.addSnpLayout()
    }
    
    private func addSnpLayout(){
        imgView.snp.makeConstraints { make in
            make.left.equalTo(10)
            make.top.equalTo(10)
            make.width.equalTo(100)
            make.height.equalTo(100)
        }
        
        titleLab.snp.makeConstraints { make in
            make.left.equalTo(imgView.snp.right).offset(10)
            make.top.equalTo(10)
            make.right.equalTo(-10)
            make.height.greaterThanOrEqualTo(30)
        }
        
        subTitleLab.snp.makeConstraints { make in
            make.left.equalTo(imgView.snp.right).offset(10)
            make.top.equalTo(titleLab.snp.bottom).offset(4)
            make.right.equalTo(-10)
            make.bottom.equalTo(0)
        }
        self.layoutIfNeeded()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
